//$Id$

package builders;

/**
 * @author Vincent
 */
public class Tile {

	private static final int MAX_DIE_VALUE = 10;
	protected String tileDescription;
	private String nameOfTile;
	private String imageFile;
	protected int multiplier; 
	protected Player.Resource resource;

	/*
	 * this is to indicate that the tile is not a homeBase of any player.
	 */
	private boolean isHomeBase = false;

	/**
	 * This is the constructor of the Tile class.
	 * 
	 * @param multiplier		the multiplier with which the tile will use to calculate the amount of resources to give to player
	 * @param resource			specify the resource that the tile will give out
	 * @param tileDescription	a description of what the tile has done
	 * @param nameOfTile		a description of what the tile can do
	 * @param imageFile			specify the file name of the image used by the tile
	 */
	public Tile(String multiplier, String resource , String tileDescription, String nameOfTile, String imageFile) {

		this.multiplier = Integer.valueOf(multiplier);
		searchResource(resource);
		this.tileDescription = tileDescription;
		this.nameOfTile = nameOfTile;
		this.imageFile = imageFile;
	}

	/**
	 * This is the constructor used by the HomeBase class. 
	 * 
	 * @param tileDescription	a description that informs the player that the player has landed on a homeBase
	 * @param nameOfTile		specify the name of the homeBase
	 * @param imageFile			specify the file name of the image used by the homeBase
	 */
	public Tile(String tileDescription, String nameOfTile, String imageFile) {

		this.tileDescription = tileDescription;
		this.nameOfTile = nameOfTile;
		this.imageFile = imageFile;
	}
	
	/**
	 * This method will match the String input to the name of a Player.Resource.
	 * 
	 * @param stringResource	the String input from the parameters of the Tile constructor
	 */
	private void searchResource(String stringResource) {
		
		for (Player.Resource resource : Player.Resource.values()){
			if (resource.toString().equals(stringResource)){
				this.resource = resource;
			}
		}

	}

	/**
	 * @return	the description of what the tile has done
	 */
	public String getTileDescription() {
		return tileDescription;
	}

	/**
	 * @return 	the description of what the tile can do
	 */
	public String getNameOfTile() {
		return nameOfTile;
	}

	/**
	 * @return 	the file name of the image used by the tile
	 */
	public String getImageFile() {
		return imageFile;
	}

	/**
	 * @return	the multiplier with which the tile will use to calculate the amount of resources to give to player
	 */
	public int getMultiplier() {
		return multiplier;
	}

	/**
	 * @return	the resource that the tile will give out
	 */
	public Player.Resource getResource() {
		return resource;
	}

	/**
	 * @return	false as the tile is not a homeBase
	 */
	public boolean getIsHomeBase() {
		return isHomeBase;
	}

	/**
	 * This is the method called by Logic to get the results of the event triggered when the player landed on a tile.
	 * 
	 * @param numberOfActionPointsLeft	the remaining Action Points that the player has after using the Action Points for movement
	 * @return							a TileResult which will specify the resource that is affected, the amount the affected resource has changed and the description of what the tile has done (NOTE: if the parameter numberOfActionPointsLeft is out of range, the TileResult return will only have errorPresent set to true. The rest of the variables will be null.) 
	 *  
	 */
	public TileResult execute(int numberOfActionPointsLeft) {
		
		if (numberOfActionPointsLeft > MAX_DIE_VALUE || numberOfActionPointsLeft < 1){
			return new TileResult(true);
		}
		
		int amountToIncrease = numberOfActionPointsLeft * multiplier;

		TileResult result = new TileResult(resource, amountToIncrease, tileDescription + amountToIncrease);
		
		return result;
	}
}